
#include <stdio.h>
#include <unistd.h>

#define LOG_BUFFER_SIZE 100
#define MAX_LOG_ENTRIES 10

typedef struct {
    double speed;
    float avg_speed;
    float distance;
    char time[12];
    char temp[10];
} LogEntry;

static LogEntry log_buffer[MAX_LOG_ENTRIES];
static int log_index = 0;
static int log_count = 0;

void add_log_entry(double speed, float avg_speed, float distance, 
                  const char* time, const char* temp) {
    if (log_count >= MAX_LOG_ENTRIES) return;
    
    LogEntry *entry = &log_buffer[log_index];
    entry->speed = speed;
    entry->avg_speed = avg_speed;
    entry->distance = distance;
    strncpy(entry->time, time, sizeof(entry->time)-1);
    strncpy(entry->temp, temp, sizeof(entry->temp)-1);
    
    log_index = (log_index + 1) % MAX_LOG_ENTRIES;
    if (log_count < MAX_LOG_ENTRIES) log_count++;
}

void print_all_logs() {
    for (int i = 0; i < log_count; i++) {
        int idx = (log_index - 1 - i + MAX_LOG_ENTRIES) % MAX_LOG_ENTRIES;
        LogEntry *entry = &log_buffer[idx];
        printf("SPEED:%.2fKM/H AVG:%.1fKM/H DIST:%.1fKM TIME:%s TEMP:%s\r\n",
               entry->speed, entry->avg_speed, entry->distance,
               entry->time, entry->temp);
    }
}